home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
dit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
97 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* dit -
* Dither pixels into 1 bit deep bits.
*
*
*/
#define MATSIZE88
#define DXSIZE 8
#define DYSIZE 8
static int ditscaled;
static short dithmat[DYSIZE][DXSIZE] = { /* halftone dots */
3, 17, 55, 63, 61, 47, 9, 1,
15, 29, 39, 51, 49, 35, 25, 13,
40, 32, 26, 20, 22, 30, 36, 42,
56, 44, 10, 4, 6, 18, 52, 58,
60, 46, 8, 0, 2, 16, 54, 62,
48, 34, 24, 12, 14, 28, 38, 50,
23, 31, 37, 43, 41, 33, 27, 21,
7, 19, 53, 59, 57, 45, 11, 5,
};
#define TOTAL (DXSIZE*DYSIZE)
dittobits(sbuf,bits,y,n)
short *sbuf;
char *bits;
int y, n;
{
short val;
int rshades, rmaxbits;
short *rdith, *rptr;
short mask;
int dx, dy;
if(!ditscaled) {
for(dy=0; dy<DYSIZE; dy++)
for(dx=0; dx<DXSIZE; dx++)
dithmat[dy][dx] = (254*dithmat[dy][dx])/63;
ditscaled = 1;
}
rdith = &dithmat[y%DYSIZE][0];
mask = 0x80;
rptr = rdith;
val = 0;
while(n) {
if(n>=8) {
if(sbuf[0] <= rptr[0])
val |= 0x80;
if(sbuf[1] <= rptr[1])
val |= 0x40;
if(sbuf[2] <= rptr[2])
val |= 0x20;
if(sbuf[3] <= rptr[3])
val |= 0x10;
if(sbuf[4] <= rptr[4])
val |= 0x08;
if(sbuf[5] <= rptr[5])
val |= 0x04;
if(sbuf[6] <= rptr[6])
val |= 0x02;
if(sbuf[7] <= rptr[7])
val |= 0x01;
sbuf+=8;
rptr = rdith;
*bits++ = val;
val = 0;
n -= 8;
} else {
if(*sbuf++ <= *rptr++)
val |= mask;
mask >>= 1;
n--;
}
}
if(mask!=0x80)
*bits++ = val;
}